{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0577a881",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Marry', 'Jan', 'jack', 'lxx', 'lit']\n",
      "['Mike', 'Marry', 'lxx', 'Jan', 'jack', 'lxx', 'lit']\n",
      "['Mike', 'Marry', 'lxx', 'Jan', 'jack', 'lxx']\n",
      "\n",
      "['Mike', 'Marry', 'lxx', 'Jan', 'jack', 'lxx']\n",
      "['Mike', 'Marry', 'Jan', 'jack', 'lxx']\n"
     ]
    }
   ],
   "source": [
    "# Author:lxx\n",
    "# date:week07\n",
    "\n",
    "# 回顾\n",
    "name_str = \"alex,marry,jack\"\n",
    "name_list = [\"alex\",\"marry\",\"jack\"]\n",
    "\n",
    "\n",
    "# 本周重点：list的方法\n",
    "# 1.取值：切片\n",
    "# 2.增加/新增数据\n",
    "\n",
    "names = [\"Mike\",\"Marry\",\"Jan\",\"jack\"]\n",
    "# 2.1 append() 圆括号的内容是 对象（比较大的一个范围，Python中一切皆是对象）\n",
    "#     append() 新增在末尾\n",
    "names.append(\"lxx\")\n",
    "names.append(\"lit\")\n",
    "print(names)\n",
    "\n",
    "# 2.2 insert() 指定位置新增数据库\n",
    "names.insert(2,\"lxx\")\n",
    "print(names)\n",
    "\n",
    "# 3.删除,remove()的操作应该先做查询，判断元素value是否存在？\n",
    "names.remove(\"lit\")\n",
    "print(names)\n",
    "\n",
    "# 先做查询：seq的一般方法（通用方法）\n",
    "print(\"\")\n",
    "\n",
    "# 3.2 pop() 在使用pop()之前，要先了解list的长度？清楚删除的索引位置\n",
    "# 要先了解list的长度？社区一般方法 len()  \n",
    "print(names)\n",
    "names.pop(2)\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c4dcd90d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)  # list() 可以将 str  to(转)  list\n",
    "print(phrase)\n",
    "print(plist)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8f84b354",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "on\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "on_str = ''.join(plist[1:3])\n",
    "print(on_str)\n",
    "new_phrase = on_str+ ''.join(plist[5]+plist[4]+plist[7]+plist[6])\n",
    "print(plist)\n",
    "print(new_phrase)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "db7f174c",
   "metadata": {},
   "outputs": [],
   "source": [
    "stu_id = [10001,10002,10003,10004,10008,10001,10009,10010,10001]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "32570d7a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_id: [10001, 10002, 10003, 10004, 10008, 10001, 10009, 10010, 10001] \n",
      " stu_id_matedata: [10001, 10002, 10003, 10004, 10008, 10001, 10009, 10010, 10001]\n"
     ]
    }
   ],
   "source": [
    "stu_id_matedata = stu_id\n",
    "print(\"stu_id:\",stu_id,'\\n','stu_id_matedata:',stu_id_matedata)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "05672e04",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_id: [10001, 10001, 10009, 10010, 10001] \n",
      " stu_id_matedata: [10001, 10004, 10008, 10001, 10009, 10010, 10001]\n"
     ]
    }
   ],
   "source": [
    "# 赋值\n",
    "stu_id.pop(1)\n",
    "print(\"stu_id:\",stu_id,'\\n','stu_id_matedata:',stu_id_matedata)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "557a3897",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_id: [10001, 10009, 10010, 10001] \n",
      " stu_id_matedata: [10001, 10004, 10008, 10001, 10009, 10010, 10001]\n"
     ]
    }
   ],
   "source": [
    "# copy()\n",
    "tu_id_matedata = stu_id.copy()\n",
    "stu_id.pop(1)\n",
    "print(\"stu_id:\",stu_id,'\\n','stu_id_matedata:',stu_id_matedata)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f12b397b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_id: [10001, 10010, 10001] \n",
      " stu_id_matedata: [10001, 10009, 10010, 10001]\n"
     ]
    }
   ],
   "source": [
    "# 切片实现复制\n",
    "stu_id_matedata = stu_id[:]\n",
    "stu_id.pop(1)\n",
    "print(\"stu_id:\",stu_id,'\\n','stu_id_matedata:',stu_id_matedata)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "abece24b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for i in stu_id:\n",
    "    # 循环遍历stu_id的所有内容\n",
    "    if i == 10001:\n",
    "        # 判断如果元素为10001的时候,怎么取出索引值呢？\n",
    "        print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2fedd85",
   "metadata": {},
   "outputs": [],
   "source": [
    "goods = [\n",
    "    [\"10001\",\"python课本\",\"88\"],\n",
    "    [\"10002\",\"蜜雪冰城—冰茶\",\"10\"],\n",
    "    [\"10003\",\"iphone13 pro\",\"9999\"],\n",
    "    [\"10004\",\"华为电-跑车\",\"400000\"],\n",
    "    [\"10005\",\"小米手环\",\"199\"]\n",
    "]\n",
    "user_shop_list = []\n",
    "\n",
    "支付宝余额 = input(\"请输入您的余额：\")\n",
    "info = '''------goods list-------\n",
    "%s\n",
    "%s\n",
    "%s\n",
    "%s\n",
    "%s\n",
    "'''%(goods[0],goods[1],goods[2],goods[3],goods[4])\n",
    "print(info)\n",
    "user_input_ID = input(\"请输入商品的ID：\")\n",
    "for good in goods:\n",
    "    print(good)\n",
    "    # 判断商品的id是否正确\n",
    "    if user_input_ID == good[0]:\n",
    "        # 判断用户的余额是否够用\n",
    "        if int(good[2]) < int(支付宝余额):\n",
    "            # 把商品加进list\n",
    "            user_shop_list.append(good)\n",
    "            # 扣除支付宝余额\n",
    "            break\n",
    "\n",
    "    else:\n",
    "        print(\"您输入的商品信息有问题，请输入正确的商品ID\")\n",
    "\n",
    "print(user_shop_list)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1a7a8bd0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
